<?php
/**
 * @author spenceryg
 * @date 2022/4/11
 * @time 11:18 上午
 * @focus love & life
 */


namespace app\wechat\lib;


use EasyWeChat\Factory;

class WechatQrcode
{


    /**
     * qrcode
     * @param string $scene
     * @return array
     */
    public static function getQrcode(string $scene = ''): array
    {
        $config = config('wechat_official_account');
        $wechat = Factory::officialAccount($config);
        $scene = $scene ?: md5(uniqid(mt_rand(), true));
        $res = $wechat->qrcode->temporary($scene, 6 * 24 * 3600);
        $url = $wechat->qrcode->url($res['ticket']);
        return ['qrcode_url'=>$url, 'qrcode_scene' => $scene];
    }
}
